package com.javabasic;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2022/1/19 9:36 下午
 */
public class AliTestTwo {


    static List<Double> result;
    static List<String> resultStr;
    static Map<String,List<Double>> resultMap;
    static double[] price = new double[]{9.99,19.99,99.99,199.99,299.99};
    static char[] chars = new char[]{'A','B','C','D','E'};

    public static void main(String[] args) {

        int PRICE_LEN = 5;
//        result = new ArrayList<>();
//        resultStr = new ArrayList<>();
        resultMap = new TreeMap<>();

        dfs(PRICE_LEN-1, 0,"");
//        Collections.sort(result);
//
//        int size = result.size();
//        System.out.println(size);
//        for (int i = 0; i < size; i++) {
//            System.out.println(result.get(i) + "-" + resultStr.get(i));
//        }

        System.out.println(resultMap.size());
        for (Map.Entry<String, List<Double>> entry : resultMap.entrySet()) {
            System.out.println(entry.getKey() + ":");
            for (Double aDouble : entry.getValue()) {
                System.out.println("     "+aDouble);
            }
        }

    }

    private static void dfs(int i, double sum, String str) {

        if (i < 0) {
            sum = sum * 0.77;
            if (sum-399.99 >= 0.000001) {
                sum -= 99.99;
//                result.add(sum);
//                resultStr.add(str);
                List<Double> orDefault = resultMap.getOrDefault(str, new ArrayList<>());
                orDefault.add(sum);
                resultMap.put(str,orDefault);

            }
            return;
        }

        dfs(i-1,sum,str);
        dfs(i-1,sum + price[i],str +chars[i]);
        dfs(i-1,sum+ price[i]*2,str+chars[i]+chars[i]);
    }
}
